<template>
  <div class="app-container">
      <div class="filter-container">
        <el-input clearable v-model="search.orderNum" placeholder="订单编号" style="width: 170px;"></el-input>
        <el-input clearable v-model="search.refundNum" placeholder="退款编号" style="width: 170px; margin-left:5px;"></el-input>
        <el-select v-model="search.type" clearable placeholder="退款状态" style="width: 130px; margin-left:5px;">
            <el-option 
            v-for="(item,index) in selectOptions.refundState"
            :key="index"
            :label="item.label"
            :value="item.value">
            </el-option>
        </el-select>
        
        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="15%" align="center" label="退款编号">
        <template slot-scope="scope">
          <span>{{ scope.row.refundNum }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="15%" align="center" label="订单编号">
        <template slot-scope="scope">
          <span>{{ scope.row.orderNum }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="15%" align="center" label="用户信息">
        <template slot-scope="scope">
          <div style="display:flex; justify-content:flex-start;align-items:center;">
            <span style="width:50px"><el-image :src="scope.row.headPortrait" style="width:40px;height:40px;border-radius:50%"></el-image> </span>
            <span style="margin-left:5px; display:flex;flex-wrap:wrap;">
              <span style="width:100%;">{{scope.row.nickName}}</span>
              <span style="width:100%;">{{scope.row.userPhone}}</span>
            </span>
          </div>
        </template>
      </el-table-column>
      <el-table-column  min-width="15%" align="center" label="课程">
        <template slot-scope="scope">
          <div style="display:flex; justify-content:flex-start;align-items:center;">
            <span style="width:50px"><el-image :src="scope.row.courseImageConvert" style="width:50px;height:50px;"></el-image> </span>
            <span style="margin-left:5px;">{{scope.row.courseName}}</span>
          </div>
        </template>
      </el-table-column>

      <el-table-column  min-width="10%" align="center" label="退款金额">
        <template slot-scope="scope">
          <span>{{ scope.row.money }}</span>
        </template>
      </el-table-column>

      <el-table-column  min-width="15%" label="退款缘由">
        <template slot-scope="scope">
            <span>{{scope.row.reason}}</span>
        </template>
      </el-table-column>
      
      <el-table-column min-width="10%" label="状态">
        <template slot-scope="scope">
            <el-tag :type="['primary','warning','success','info','danger'][scope.row.state]">{{scope.row.state | parseRefundState}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column  min-width="10%" align="center" label="时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  min-width="15%">
        <template slot-scope="scope">
          <router-link :to="'/ordermanage/refunddetail/'+scope.row.id">
            <el-button type="primary" size="small">
              详情
            </el-button>
          </router-link>
          
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="getList" />
  </div>
</template>

<script>

import { deepClone,parseTime } from '@/utils'
import * as auth from '@/utils/auth'
import * as courseApi from '@/api/courseinfo'
import * as shopApi from '@/api/shop'
import * as orderApi from '@/api/orders'
import * as uploadApi from '@/api/upload'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import BxImage from '@/components/BxImage'
import guid from '@/utils/guid'
import * as imageHelper from '@/utils/image'
import * as enumHelper from '@/utils/enum'

export default {
  name: 'RefundInfoShop',
  components: { Pagination,BxImage },
  data(){
    return{
      list: null,
      courseList:[],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        rows: 20,
        orderName:'',
        orderNum:'',
        type:-1,
      },
      search:{
        orderName:'',
        orderNum:'',
        type:'',
      },
      selectOptions:{
          refundState:null,
          // [
          //     {label:'待处理',value:'1'},
          //     {label:'已退款',value:'2'},
          // ],
      }
    }
  },
  created(){
      var that=this;
      that.getList();
      that.selectOptions.refundState=[];
      Object.values(enumHelper.refund.refundState).map(v=>{
        if(typeof(v)!='number'){return;}
        that.selectOptions.refundState.push({label:enumHelper.refund.refundState.getName(v),value:v});
      })
  },
  mounted(){

  },
  filters:{
    parseRefundState(state){
      return enumHelper.refund.refundState.getName(state)
    }
  },
  methods: {
    getList(){
      var that=this;
      that.listLoading = true;
      orderApi.getRefundList(that.listQuery).then(res=>{
         if(res.data){
            that.list=[...res.data.items.map((item,index)=>{
              item._id=index+1;
              item.courseImageConvert=imageHelper.GetFullUrl(item.courseImage,200,200);
              return item;
            })];
            that.listLoading = false;
            that.total=res.data.total;
         }
      })
    },
    searchClick(){
      var that=this;
      that.listQuery.page=1;
      that.listQuery.orderName=that.search.orderName;
      that.listQuery.orderNum=that.search.orderNum;
      that.listQuery.type=that.search.type || -1;
      that.getList();
    },
    
  }
}
</script>
